package com.example.memo1.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.memo1.R;
import com.example.memo1.dao.AdminDao;

public class LoginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);





        //注册按钮
        Button register=findViewById(R.id.login_register);
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent1);
            }
        });

        //登录按钮
        EditText ac=findViewById(R.id.login_zh);
        EditText pwd=findViewById(R.id.login_pwd);

        Button bu=findViewById(R.id.login_login);
        bu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                 String acT=ac.getText().toString().trim();
                 String pwdT=pwd.getText().toString().trim();
                 if(acT.isEmpty()){
                     Toast.makeText(LoginActivity.this, "请输入账号", Toast.LENGTH_SHORT).show();
                 } else if (pwdT.isEmpty()) {
                     Toast.makeText(LoginActivity.this,"请输入密码",Toast.LENGTH_SHORT).show();
                 }else{
                     AdminDao adminDao=new AdminDao();
                     int a=adminDao.loginAdmin(acT,pwdT);
                     if(a==0){
                         Toast.makeText(LoginActivity.this,"账号不存在或密码错误",Toast.LENGTH_SHORT).show();
                     }else{
                         Toast.makeText(LoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
                         Intent intent1=new Intent(LoginActivity.this,MainActivity.class);
                         intent1.putExtra("account",acT);
                         startActivity(intent1);
                     }
                 }
            }
        });



    }
}
